package com.zlh123.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.zlh123.mapper")
public class MybatisPlusConfig {
    //配置分页拦截器插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
//    // 1. 插入时自动填充
//    @Override
//    public void insertFill(MetaObject metaObject) {
//        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
//        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
//    }
//
//    // 2. 更新时自动填充
//    @Override
//    public void updateFill(MetaObject metaObject) {
//        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
//    }
}
